﻿// Copyright 2007, 2008 - Ariel Yaroshevich (a.k.a blackrussian) (hamlet@inter.net.il)
// This file is part of SharpMap.
// SharpMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// SharpMap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using SharpMap.Rendering.Rendering2D;
using System.Windows.Media;
using Smg = SharpMap.Geometries;

using SharpMap.Rendering;
using SharpMap.Wpf.Rendering;

namespace SharpMap.Presentation.Wpf.Converters
{
    //public class FeatureConverter : IValueConverter
    //{

    //    FeatureRenderer _renderer = new FeatureRenderer(new VectorRenderer());
    //    SharpMap.Wpf.Rendering.LayerStyle _style;
    //    public FeatureConverter()
    //    {
    //        SetStyle();
    //    }

    //    private void SetStyle()
    //    {
    //        _style = new SharpMap.Wpf.Rendering.LayerStyle();
    //        _style.NormalGeometry.Line = new Pen(Brushes.DarkBlue, 0.3);
    //        //if (vStyle.EnableOutline)
    //        //{
    //        //    _style.NormalGeometry.Outline = (Pen)ViewConverter.Convert(vStyle.Outline).Clone();
    //        //}
    //        //_style.NormalGeometry.Fill = (Brush)ViewConverter.Convert(vStyle.Fill).Clone();

    //        //if (vStyle.HighlightLine != null)
    //        //{
    //        //    _style.HighlightedGeometry.Line = (Pen)ViewConverter.Convert(vStyle.HighlightLine).Clone();
    //        //}
    //        //if (vStyle.HighlightOutline != null)
    //        //{
    //        //    _style.HighlightedGeometry.Outline = (Pen)ViewConverter.Convert(vStyle.HighlightOutline).Clone();
    //        //}
    //        //if (vStyle.HighlightFill != null)
    //        //{
    //        //    _style.HighlightedGeometry.Fill = (Brush)ViewConverter.Convert(vStyle.HighlightFill).Clone();
    //        //}

    //        //if (vStyle.SelectLine != null)
    //        //{
    //        //    _style.SelectedGeometry.Line = (Pen)ViewConverter.Convert(vStyle.SelectLine).Clone();
    //        //}
    //        //if (vStyle.SelectOutline != null)
    //        //{
    //        //    _style.HighlightedGeometry.Outline = (Pen)ViewConverter.Convert(vStyle.SelectOutline).Clone();
    //        //}

    //        //if (vStyle.SelectFill != null)
    //        //{
    //        //    _style.SelectedGeometry.Fill = (Brush)ViewConverter.Convert(vStyle.SelectFill).Clone();
    //        //}


    //        //if (vStyle.Symbol != null)
    //        //{
    //        //    _style.NormalPoint = new PointStyle();
    //        //    _style.NormalPoint.ImageSource = SharpMap.Wpf.Rendering.Resources.DefaultSymbol;

    //        //    _style.SelectedPoint = new PointStyle();
    //        //    _style.SelectedPoint.ImageSource = SharpMap.Wpf.Rendering.Resources.DefaultSelectedSymbol;
    //        //    _style.HighlightedPoint = new PointStyle();
    //        //    _style.HighlightedPoint.ImageSource = SharpMap.Wpf.Rendering.Resources.DefaultHighlightedSymbol;

    //        //}
    //        //else
    //        //{
  
    //        //}
    //        _style.NormalPoint = new PointStyle();
    //        _style.NormalPoint.Size = new System.Windows.Size(2, 2);
    //        _style.NormalPoint.ImageSource = SharpMap.Wpf.Rendering.Resources.DefaultSymbol;
   
    //        _style.NormalGeometry.Fill = new SolidColorBrush(Colors.BurlyWood);
            
    //    }


    //    #region IValueConverter Members
    //    SharpMap.Styles.VectorStyle dummy = new SharpMap.Styles.VectorStyle();
    //    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    //    {
    //        if (!typeof(Drawing).IsAssignableFrom(targetType))
    //            return null;

    //        SharpMap.Data.IFeatureDataRecord sourceFeature = value as SharpMap.Data.IFeatureDataRecord;
    //        if (sourceFeature != null)
    //        {

    //            IEnumerable<Drawing> drawings =
    //                _renderer.RenderFeature(sourceFeature, dummy, RenderState.Normal);
    //            Drawing retVal = null;
    //            int nDrawing = 0;
    //            foreach (Drawing d in drawings)
    //            {
    //                if (nDrawing == 0)
    //                {
    //                    retVal = d;
    //                    ++nDrawing;
    //                }
    //                else if (nDrawing == 1)
    //                {
    //                    DrawingGroup g = new DrawingGroup();
    //                    using (DrawingContext ctx = g.Append())
    //                    {
    //                        ctx.DrawDrawing(retVal);
    //                        ctx.DrawDrawing(d);
    //                    }
    //                    retVal = g;
    //                    ++nDrawing;
    //                }
    //                else
    //                {
    //                    using (DrawingContext ctx = ((DrawingGroup)retVal).Append())
    //                    {
    //                        ctx.DrawDrawing(d);
    //                    }
    //                }

    //                ContentLayerPanel.SetWorldX(retVal, retVal.Bounds.X);
    //                ContentLayerPanel.SetWorldY(retVal, retVal.Bounds.Y);
    //                return retVal;
    //            }

    //        }
    //        return null;
    //    }

    //    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    #endregion
    //}
}
